package com.example.healthcode2.Other;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.widget.Toast;

public class GpsReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        System.out.println("GpsReceiver广播启动");
        if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
            Intent intent1=new Intent(context,GpsService.class);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                context.startForegroundService(intent1);//android8.0以上需要启动前台服务
            }else {
                context.startService(intent1);
            }
            Toast.makeText(context, "启动gpsService", Toast.LENGTH_SHORT).show();
        }
    }
}
